package ocean.chinacraft.common.world.item.tool;

import ocean.chinacraft.common.config.GroupDefine;
import ocean.chinacraft.common.world.item.tool.base.ModItemTier;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.world.World;

import javax.annotation.Nonnull;

/**
 * 青铜大刀 - 碧玉
 *
 * @author zhang
 * @since 2021/12/3
 */
public class BronzeSwordJasper extends SwordItem {

    public BronzeSwordJasper() {
        super(ModItemTier.BRONZE_SWORD_JASPER, 3, -2.4F, new Properties()
                .tab(GroupDefine.CHINACRAFT_TOOL).stacksTo(1));
    }

    @Override
    public void inventoryTick(@Nonnull ItemStack itemStack, @Nonnull World world, @Nonnull Entity entity, int index, boolean flag) {
        if (entity instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) entity;
            if (!player.getMainHandItem().isEmpty() && player.getMainHandItem() == itemStack) {
                player.addEffect(new EffectInstance(Effects.DAMAGE_RESISTANCE, 20, 0, false, false));
            }
        }
    }
}
